package com.yuan;

import com.yuan.pojo.SysDept;
import com.yuan.pojo.企业.AxdFirm;
import com.yuan.service.SysDeptService;
import com.yuan.service.企业.AxdFirmService;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/*
 *  @author 雨安
 *  类名： TreeDataApplication
 *  创建时间：2024/4/11
 */
@SpringBootTest
public class TreeDataApplication {
    @Resource
    private AxdFirmService firmService;

    @Resource
    private SysDeptService sysDeptService;

    @Test
    void haha(){
        //创建批量添加集合
        List<SysDept> axdList = new LinkedList<>();
        //拿到企业数据
        List<AxdFirm> list = firmService.list(null);
        //遍历企业数据
        for (int i = 0; i < list.size(); i++) {
            //判断不为null
            if (list.get(i)!=null){
                //创建实体类
                SysDept sysDept = new SysDept();
                //设置父部门id
                sysDept.setParentId(0L);
                //设置部门名称
                if (StringUtils.isNotBlank(list.get(i).getName())){
                    sysDept.setDeptName(list.get(i).getName());
                }
                //设置祖籍列表
                sysDept.setAncestors("0");
                //设置负责人
                sysDept.setLeader("admin");
                //设置状态
                sysDept.setStatus("0");
                //设置是否逻辑删除
                sysDept.setDelFlag("0");
                //创建创建时间
                sysDept.setCreateBy("admin");
                sysDept.setCreateTime(new Date());
                sysDept.setUpdateBy("admin");
                sysDept.setUpdateTime(new Date());
                sysDept.setAxdSystemType("FIRM");
                //设置企业id
                sysDept.setFirmId(list.get(i).getId());
                //将数据添加到集合中
                axdList.add(sysDept);
            }
        }//fori结束
        //执行添加sql
        sysDeptService.saveBatch(axdList);
    }


}
